package nju.bishe.weibo.service;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

import weibo4android.Status;
import weibo4android.Weibo;
import weibo4android.WeiboException;

/**
 * 
 * @author longwei.wu
 * @version $Id: LaughChannelService.java, v 0.1 2011-3-27 下午08:00:25 longwei.wu Exp $
 */
public class LaughChannelService {
    
	 Weibo mWeibo;
	 String userId = "2048648067";
    /**
     * 用爆料频道的ID把文章发上去
     * 
     * @param status
     */
    public void updateStatus(String content){
      
    	mWeibo = getWeiboInstance();
        
        try {
        	mWeibo.updateStatus(content);
        } catch (WeiboException e) {
            e.printStackTrace();
        }
    }
    
    /**
     * 上传一张图片并发一条微博
     * 
     * @param content
     *          要发的新微博的文字内容
     * @param filePath
     *          上传图片的地址
     */
    public void updateStatus(String content,String filePath){
    	mWeibo = getWeiboInstance();
        
        try {
            File file=new File(filePath);
            content = URLEncoder.encode(content,"UTF-8");
            mWeibo.uploadStatus(content,file);
        } catch (WeiboException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    
    public void updateStatus(String content,File file){        
    	mWeibo = getWeiboInstance();
        

            try {
				content = URLEncoder.encode(content,"UTF-8");
				mWeibo.uploadStatus(content,file);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (WeiboException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
           
  
    }
    
    public List<Status> getStatus(int page){       
    	mWeibo= getWeiboInstance();
       
        List<Status> status = null;
        try {
            status = mWeibo.getUserTimeline(userId, page);
        } catch (WeiboException e) {
 
        }
        
        return status;
    }
    
    public String getUserId(){
		return userId;
    	
    }
    public Weibo getWeiboInstance(){
        Weibo weibo = new Weibo();
        weibo.setToken("bf733885aad28b5a1dbc636ec8edcd84", "47552258a8e6744bdcb7116a0d229636");
        return weibo;
    }
    

}
